package com.cityfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfCartMapper;
import com.cityfood.pojo.CfCart;
import com.cityfood.pojo.CfCartExample;
import com.cityfood.pojo.CfCartExample.Criteria;
import com.cityfood.service.CartService;

@Service
public class CartServiceImpl implements CartService {

	@Autowired
	private CfCartMapper cartMapper;

	@Override
	public CfCart getCartByUserId(Integer userId) {
		CfCartExample example = new CfCartExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<CfCart> list = cartMapper.selectByExample(example);
		if (list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public int saveCart(CfCart cart) {
		int i = cartMapper.insertSelective(cart);
		return i;
	}

	@Override
	public int updateCart(CfCart cart) {
		int i = cartMapper.updateByPrimaryKeySelective(cart);
		return i;
	}

	@Override
	public int deleteCart(CfCart cart) {
		int i = cartMapper.updateByPrimaryKeySelective(cart);
		return i;
	}

}
